<?php

require_once dirname(__FILE__) . '/../Entry.php';
require_once dirname(__FILE__) . '/../Rats.php';
require_once dirname(__FILE__) . '/Extension/OverlayContent.php';

class Rats_OverlayEntry extends Raws_Entry
{

    protected $_entryClassName = 'Rats_OverlayEntry';

    public function __construct($element = null)
    {
        // foreach (Rats::$namespaces as $nsPrefix => $nsUri) {
        //     $this->registerNamespace($nsPrefix, $nsUri); 
        // }
        parent::__construct($element);
    }

    public function getDOM($doc = null)
    {
        $element = parent::getDOM($doc);
        // Appending the content element is already done by the base class (= Zend_Gdata_App_Entry) getDOM()
        // BY DOING IT HERE, the content element will be present twice if you call getXML()
        // if ($this->_content != null) {
        //     $element->appendChild($this->_content->getDOM($element->ownerDocument));
        // }
        return $element;
    }

    protected function takeChildFromDOM($child)
    {
        $absoluteNodeName = $child->namespaceURI . ':' . $child->localName;
        switch ($absoluteNodeName) {
        case $this->lookupNamespace('atom') . ':' . 'content':
            $content = new Rats_Extension_OverlayContent();
            $content->transferFromDOM($child);
            $this->_content = $content;
            break;
        default:
            parent::takeChildFromDOM($child);
            break;
        }
    }
}